<template>
  <div id="app">
    <button @click="uploadExcel">上传</button>
    <button @click="downloadExcel">下载</button>
    <div id="luckysheet" style="width: 100vw; height: 90vh"></div>
  </div>
</template>

<script>
import LuckyExcel from "luckyexcel";
import { exportExcel } from "./export";
import createFileInput from "create-file-input";
export default {
  name: "HelloWorld",
  mounted() {
    window.luckysheet.create({
      container: "luckysheet",
    });
  },
  methods: {
    uploadExcel() {
      createFileInput({
        multiple: false,
        fileOnly: true,
        onChange: (file) => {
          LuckyExcel.transformExcelToLucky(file, (exportJson) => {
            window.luckysheet.destroy();

            window.luckysheet.create({
              container: "luckysheet",
              showinfobar: false,
              data: exportJson.sheets,
              title: exportJson.info.name,
              userInfo: exportJson.info.name.creator,
            });
          });
        },
      });
    },
    downloadExcel() {
      exportExcel(window.luckysheet.getAllSheets(), "下载");
    },
  },
};
</script>
